<?php

if(!defined("INDEX"))
    die;
    
if(!check_request('type'))
    $type = 'everywhere';
else
    $type = trim($_REQUEST['type']);
    
if(!check_request('string') || empty($_REQUEST['string'])) {
    header('Location: /');
    exit;
}

// ----------------------------------------------------------------------------

$search = new Search;

$s_artists = null;
$s_releases = null;

switch($type) {

    case 'artists':

        $s_artists = $search->searchArtists($_REQUEST['string']);

        $smarty->assign('artists', $s_artists);
        break;
    case 'releases':

        $s_releases = $search->searchReleases($_REQUEST['string']);

        $smarty->assign('releases', $s_releases);
        break;
    case 'everywhere':
    default:

        $s_artists = $search->searchArtists($_REQUEST['string']);
        $s_releases = $search->searchReleases($_REQUEST['string']);

        $smarty->assign('artists', $s_artists);
        $smarty->assign('releases', $s_releases);
        break;

}

if(empty($s_artists) && empty($s_releases))
    $smarty->assign('not_found', true);